/**
 * Created by Administrator on 15-11-27.
 */
var NavigationBar = RichBase.extend({
	EVENTS : {
		"click" : {
			".navBtn" : "onNavBtnClick"
		}
	},
	init : function(){
		this.container = $("#navigationBar");
		this.currentPage = $("#whichPageInp");
		this.totalPage = $("#totalPageInp");
		this.nextBtn = $("#nextPageBtn");
		this.prevBtn = $("#prevPageBtn");
		this.tpl = $("#navigaionbar_tpl").html();
	},
	onNavBtnClick : function(that,e){
		var tarBtn = $(e.currentTarget);
		if(tarBtn.hasClass("disable")) return false;
		var current_page = $("#whichPageInp").text() * 1;
		var newPage = tarBtn.hasClass("next") ? (current_page+1) : (current_page-1)
		that.fire("navigation",{
			dir : tarBtn.hasClass("next") ? "next" : "prev",
			current_page : current_page,
			new_page : newPage
		})
	},
	render : function(data){
		var current_page = data.current_page;
		var total_page = data.total_page;
		var nextBtnCls = "";
		var prevBtnCls = "";
		if(current_page==1 && total_page==1){
			nextBtnCls = "disable";
			prevBtnCls = "disable";
		}else if(current_page==total_page){
			nextBtnCls = "disable";
		}else if(current_page==1){
			prevBtnCls = "disable";
		}
		var html = this.parseTemplate(this.tpl,{
			current_page : current_page,
			total_page : total_page,
			nextBtnCls : nextBtnCls,
			prevBtnCls : prevBtnCls
		});
		this.container.html(html);
	},
	show : function(){
		this.container.show();
	},
	hide : function(){
		this.container.hide();
	}
});
module.exports = NavigationBar;